package com.web.music.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.web.music.model.Album;
import com.web.music.model.Artist;
import com.web.music.model.Catalog;
import com.web.music.model.Genre;
import com.web.music.model.Person;

import com.web.music.model.Track;


/**
 * Loads XML files from local file system
 */
public class LocalMusicProcessor extends BaseMusicProcessor {

	String personsFilePath;
	String catalogFilePath;

	public void execute(){
		super.execute();
		Map<String,Person> persons = getXmlParser().extractPersons(new File(personsFilePath));
		getPersistence().saveAll(new ArrayList<Person>(persons.values()));
		Catalog catalog = getXmlParser().extractCatalog(new File(catalogFilePath), persons);
		getPersistence().saveAll(new ArrayList<Genre>(catalog.getGenres()));
		getPersistence().saveAll(new ArrayList<Artist>(catalog.getArtists()));
		getPersistence().saveAll(new ArrayList<Album>(catalog.getAlbums()));

		
		Track a = new Track();
		Track a1 = new Track();
		Track a2 = new Track();
		
		a.setId(2L);
		a.setTitle("aaa");
		
		byte[] b = new byte[5];
		b[0] = 1;
		b[1] = 1;
		b[2] = 1;
		b[3] = 1;
		b[4] = 1;
		
		a.setContent(b);
		
		List<Track> l =  new ArrayList<Track>();
		l.add(a);
		
		a1.setId(3L);
		a1.setTitle("aaa111");
		
		b[0] = 2;
		b[1] = 2;
		b[2] = 2;
		b[3] = 2;
		b[4] = 2;
		
		a1.setContent(b);
		
		l.add(a1);
		a2.setId(4L);
		a2.setTitle("aaa111222");
		a2.setContent(b);
		l.add(a2);
		getPersistence().saveAll(new ArrayList<Track>(catalog.getTracks()));
		//getPersistence().saveAll(new ArrayList<Track>(l));
	}	
	
	
	public String getPersonsFilePath() {
		return personsFilePath;
	}

	public void setPersonsFilePath(String personsFilePath) {
		this.personsFilePath = personsFilePath;
	}

	public String getCatalogFilePath() {
		return catalogFilePath;
	}

	public void setCatalogFilePath(String catalogFilePath) {
		this.catalogFilePath = catalogFilePath;
	}
	
}
